<template>
  <div class="live-room-box">
    <component :is="isLsPoScreen" :roomInfo="roomInfo"></component>
    <!--私密直播-->
    <Private
      v-if="isPrivate"
      :privateWords="roomInfo.roomInfo.privateWords"
      @sendFather="childCallBackPrivate"
      type="liveCom"
    ></Private>
    <!-- 关播提示 组件 -->
    <liveOffTip
      :roomInfo="roomInfo.roomInfo"
      v-if="tipOff"
      :videoMakeTip="videoMakeTip"
    ></liveOffTip>
  </div>
</template>
<script>
import LscreenLive from "./components/landscapeLiveCom.vue"; //横屏直播
import PortraitScreenLive from "@/pages/liveRoomPages/components/portraitScreenCom.vue"; //竖屏直播
import Private from "@/components/privateComponent";
import liveOffTip from "@/pages/liveRoomPages/components/liveOffTip.vue"; //关播提示

export default {
  components: {
    LscreenLive, //横屏直播
    PortraitScreenLive, //竖屏直播
    Private, //私密直播
    liveOffTip,
  },
  data() {
    return {
      isLsPoScreen: "", //横屏竖屏
      roomId: this.$route.params.roomid, //房间id
      isPrivate: false, //私密直播
      roomInfo: {}, //房间信息
      tipOff: false, //关播提示
      videoMakeTip: null, //视频制作提示
    };
  },
  computed: {
    gsTipShow() {
      //国盛风险提示开关
      return this.$store.state.showGsTip;
    }
  },
  created() {
    this.getRoomInfo();
  },
  mounted() {
    this.$store.dispatch("hideNav");
  },
  destroyed() {
    this.$store.dispatch("setShowGsTip", false);
  },
  methods: {
    getRoomInfo() {
      this.$http
        .get("/h5live/getRoomInfo?roomId=" + this.roomId + "&newRoom=true")
        .then(
          res => {
            if (res.data.code == "000000") {
              this.roomInfo = res.data.data;
              let data = res.data.data;
              let { mode } = this.roomInfo.roomInfo;
              window.sessionStorage.setItem("mode", mode);
              //0是预告 1是开播  2 是关播
              // res.data.data.roomInfo.roomStatus = 2
              if (data.roomInfo.roomStatus == 2) {
                //关播
                this.checkBackVideo(data.roomInfo.sid);
              } else {
                //预告 或者 直播
                if (this.$route.params.channel == data.roomInfo.channel) {
                  //是否匹配channel
                  if (this.$channel == "zyzq" && isZyzqApp) {
                    //是app
                    //分别给预告和直播添加查询参
                    if (data.roomInfo.roomStatus == 1) {
                      //直播
                      this.$router.push({
                        path: `/${this.$channel}/liveRoom/${this.roomId}`,
                        query: {
                          pageIs: "live"
                        }
                      });
                    } else {
                      //预告
                      this.$router.push({
                        path: `/${this.$channel}/liveRoom/${this.roomId}`,
                        query: {
                          pageIs: "preview"
                        }
                      });
                    }
                  }
                  //是否私密直播
                  if (
                    data.roomInfo.isprivate == "1" &&
                    data.roomInfo.isRestrict == "0"
                  ) {
                    //私密直播  1   0  不是           是否第一次验证   0是第一次   1  不是第一次
                    this.isPrivate = true;
                  } else {
                    //进入直播间 判断 横屏 竖屏
                    if (data.roomInfo.mode == 0) {
                      //默认横屏
                      this.isLsPoScreen = "LscreenLive";
                    } else if (data.roomInfo.mode > 0) {
                      //竖屏
                      this.isLsPoScreen = "PortraitScreenLive";
                    }
                  }
                } else {
                  //不匹配
                  console.log("进入房间机构号不匹配");
                  this.$router.replace(`/${this.$channel}/home`);
                }
              }
            }
          },
          err => {}
        );
    },
    checkBackVideo(sid) {
      //跳转回看
      this.$http
        .get("/h5live/getBackId", {
          params: {
            sceneId: sid //场次id
          }
        })
        .then(
          res => {
            if (res.data.code == "000000") {
              console.log("跳转到视频回看页面");
              if (res.data.data.id) {
                this.$router.replace(
                  `/${this.$channel}/liveBack/${res.data.data.id}`
                );
              } else {
                console.log("返回成功但返回id为空");
              }
            } else if (res.data.code == "100013") {
              this.videoMakeTip = true;
              this.tipOff = true;
            } else if (res.data.code == "100012") {
              this.videoMakeTip = false;
              this.tipOff = true;
            }
          },
          err => {
            console.log(err);
          }
        );
    },
    childCallBackPrivate() {
      //关闭私密直播
      this.isPrivate = false;
      if (this.roomInfo.roomInfo.mode == "0") {
        //横屏
        this.isLsPoScreen = "LscreenLive";
      } else if (this.roomInfo.roomInfo.mode == "1") {
        //竖屏
        this.isLsPoScreen = "PortraitScreenLive";
      }
    },
  }
};
</script>

<style scoped="scoped">
.live-room-box {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: white;
  position: fixed;
  top: 0;
  left: 0;
}
</style>
